package com.system.user.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.system.annotation.SystemServiceLog;
import com.system.common.util.Constants;
import com.system.user.dao.UserRepository;
import com.system.user.entity.User;
@Service
@Transactional
public class UserService implements IUserService{
	@Autowired
	private UserRepository userRepository;
	@SystemServiceLog(description=Constants.ADMIN_SAVE_OPTIONS,tableType=Constants.ADMIN_TABLE_TYPE)
	public void saveOrUpdate(User user) {
		userRepository.save(user);
	}
	
	public void delete(User user) {
		userRepository.delete(user);
	}
	@Transactional(readOnly = true)
	public User find(String id) {
		return userRepository.findUserByUid(id);
	}
	
	@Transactional(readOnly = true)
	public List<User> findAll() {
		return (List<User>) userRepository.findAll();
	}
	@Override
	public User findOne(String id) {
		// TODO Auto-generated method stub
		return userRepository.findUserByUid(id);
	}
	@Override
	public void update(User user) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public User findUser(String userName, String password) {
		
		return userRepository.findUser(userName, password);
	}
	@Override
	public int deleteUser(String[] ids) {
		return userRepository.deleteUser(ids);
	}
	@Override
	public int updateUser(String password, String id) {
		return userRepository.updateUser(password, id);
	}
	@Override
	public Page<User> findPage(String userName, Pageable pageable) {
		return userRepository.findPage(userName, pageable);
	}
	@Override
	public Page<User> findAll(Specification<User> spec, Pageable pageable) {
		return userRepository.findAll(spec, pageable);
	}
	@Override
	public void delete(List<String> ids) {
		List<User>users =  (List<User>) userRepository.findAll(ids);
		if(users!=null) {
			userRepository.delete(users);
		}
		
	}	
}
